Next Previous Table of Contents

The Monty Class

#include "monty.hxx"

Who is this Class for?

Who is this Section not for?

If this is you, you can safely skip this section and are finished the documentation unless you want to look at the references.

Warning to Users of this Class

Currently this class uses methods in the LInteger and LMath classes. Later versions of this library will probably be modified so that the class only calls methods in LMisc and BMath. This should make porting the methods to other languages much easier. The interface will change somewhat once this happens, though. The basic purpose of the class will remain the same, however: To save information required to do fast modular multiplication in a given base.

The Definition of "Base" Here

When this section refers to the "base of the calling instance" it, technically, means the cardinality of the residue class of the Montgomery representtaion. This will equal the value of the LInteger the class was created with.

Public Variables

TScratch

unsigned int* Monty::TScratch;

Let N be the base the calling instance was created to do modular operations in. Then TScratch is a buffer for numbers with up to one more than two times the number of digits as N.

Public Methods

Constructor From a LInteger

Monty::Monty(const LInteger& N);

Creates an object which saves information for converting magnitudes to and from the Montgomery representation for the residue class of N, and for doing arithmetic with these residues.

MontyReduceTScratch

inline void Monty::MontyReduceTScratch();

Replaces the magnitude in TScratch by the product of R^{-1} for the calling instance and the magnitude in TScratch before the method was called. (See Montgomery (1985) for defintions)

MontyMultiply

inline void Monty::MontyMultiply(const unsigned int* a, const unsigned int* b, unsigned int* result);

If a and b are the Montgomery representations of some integers x and y, then this method will put the Montgomery representation of the product of x and y into result. a and b must have the same number of digits as the base the calling instance was created for, and at least one of the two must already be less than this base. The result will have the same number of digits as the base the calling instance was created for.

MontySquare

inline void Monty::MontySquare(const unsigned int* a, unsigned int* result);

If a is the Montgomery representation of some integer x then this method will put the Montgomery representation of the square of x into result. a must have the same number of digits as the base the calling instance was created for, and must be less than this base. The result will have the same number of digits as the base the calling instance was created for.

ConvertToMonty

inline void Monty::ConvertToMonty(unsigned int* a);

Converts the magnitude pointed to by a to its Montgomery representation in the base the calling instance was created for. a must point to a magnitude having the same number of digits as the base of the calling instance.

ConvertFromMonty

inline void Monty::ConvertFromMonty(unsigned int* a);

Converts the Montgomery representation a points to back to an integer. a must point to a magnitude having the same number of digits as the base of the calling instance.


Next Previous Table of Contents